/*
ID: guoxu1
PROG: transform
LANG: C++
*/
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
using namespace std;

#define cin fin
#define cout fout

class Pattern
{
public:
	Pattern( int w )
	{
		memset( data, 0, sizeof(data) );
		this->width = w;
	}

	inline void Set( int row, int cloumn, int value )
	{
		data[ (row << 4) + cloumn ] = value;
	}

	inline int Get( int row, int cloumn ) const
	{
		return data[ (row << 4) + cloumn];
	}

	Pattern Rotate90() const
	{
		Pattern t( width );
		for( int r = 0; r < width; r++ )
		{
			for( int c = 0; c < width; c++ )
			{
				t.Set(c, width - r - 1, this->Get(r, c) );
			}
		}
		return t;
	}

	Pattern Reflect() const
	{
		Pattern t( width );
		for( int r = 0; r < width; r++ )
		{
			for( int c = 0; c < width; c++ )
			{
				t.Set(r, width - c - 1, this->Get(r, c) );
			}
		}
		return t;
	}

	bool Equal( const Pattern& p ) const
	{
		for( int r = 0; r < width; r++ )
		{
			for( int c = 0; c < width; c++ )
			{
				if( p.Get(r, c) != this->Get(r, c) )
				{
					return false;
				}
			}
		}
		return true;
	}
private:
	int data[256];
	int width;
};

int slove( const Pattern& s, const Pattern& d )
{
	Pattern t = s.Rotate90();
	if( t.Equal( d ) ) return 1;
	t = t.Rotate90();
	if( t.Equal( d ) ) return 2;
	t = t.Rotate90();
	if( t.Equal( d ) ) return 3;
	t = s.Reflect();
	if( t.Equal( d ) ) return 4;
	t = t.Rotate90();
	if( t.Equal( d ) ) return 5;
	t = t.Rotate90();
	if( t.Equal( d ) ) return 5;
	t = t.Rotate90();
	if( t.Equal( d ) ) return 5;
	if( s.Equal( d ) ) return 6;
	return 7;
}


int main()
{
	ifstream fin( "transform.in" );
	ofstream fout( "transform.out" );

	int N = 0;
	cin >> N;
	string str;
	getline( cin, str );
	
	Pattern s( N );
	Pattern d( N );
	for( int i = 0; i < N; i++ )
	{
		getline( cin, str );
		for( int j = 0; j < N; j++ )
		{
			s.Set( i, j, str[j] == '@' ? 1 : 0 );
		}
	}
	for( int i = 0; i < N; i++ )
	{
		getline( cin, str );
		for( int j = 0; j < N; j++ )
		{
			d.Set( i, j, str[j] == '@' ? 1 : 0 );
		}
	}
	int r = slove( s, d );
	cout << r << endl;

	return 0;
}
